#pragma once
#include <string>
#include <cstddef>
#include <odb/nullable.hxx>
#include <odb/core.hxx>


namespace xu
{
    #pragma db object
    class User
    {
    friend class odb::access;
    public:
        User(const std::string &user_id,const std::string &nickname, const std::string &password)
        :_user_id(user_id),
        _nickname(nickname),
        _password(password)
        {}
        User(const std::string &user_id,const std::string &phone_number)
        :_user_id(user_id),
        _phone_number(phone_number)
        {}
        User(){}

        void user_id(const std::string & user_id){ _user_id = user_id;}
        std::string user_id()
        {
            return _user_id;
        }
        
        std::string nickname()
        {
            if(!_nickname)
            {
                return std::string();
            }
            return *_nickname;
        }
        void nickname(const std::string &nickname){ _nickname = nickname;}

        std::string phone_number()
        {
            if(!_phone_number)
            {
                return std::string();
            }
            return *_phone_number;
        }
        void phone_number(const std::string &phone_number){_phone_number = phone_number;}

        std::string description()
        {
            if(!_description)
            {
                return std::string();
            }
            return *_description;
        }
        void description(const std::string &description){_description = description;}

        std::string avatar_id()
        {
            if(!_avatar_id)
            {
                return std::string();
            }
            return *_avatar_id;
        }
        void avatar_id(const std::string &avatar_id){_avatar_id = avatar_id;}

        std::string password()
        {
            if(!_password)
            {
                return std::string();
            }
            return *_password;
        }
        void password(const std::string &password){_password = password;}


    private:
        #pragma db id auto // 表示 ID 字段将自动生成（通常是数据库中的主键）。
        unsigned long _id;

        #pragma db unique type("VARCHAR(63)")
        std::string _user_id;       //用户id
        #pragma db unique type("VARCHAR(127)")
        odb::nullable<std::string> _nickname;     //用户昵称
        #pragma db unique type("VARCHAR(20)")
        odb::nullable<std::string> _phone_number;  //用户手机号码
        #pragma db type("VARCHAR(255)")
        odb::nullable<std::string> _description;   //用户个性签名
        #pragma db type("VARCHAR(63)")    
        odb::nullable<std::string> _avatar_id;     //头像id
        #pragma db type("VARCHAR(63)")
        odb::nullable<std::string> _password;      //用户密码
    };

} 